package com.example.shiyandemo;


import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@org.aspectj.lang.annotation.Aspect
public class Aspect {

    @Pointcut("@annotation(com.example.shiyandemo.Annotation.AutoFull)")
    public void method(){};


    @Before("method()")
    public void befortest(JoinPoint proceedingJoinPoint) {


        Object[] args = proceedingJoinPoint.getArgs();
        String name =(String) args[0];
        LocalDateTime now = LocalDateTime.now();

        String log = "名字："+name + "在时间为："+now+"时执行before操作";
        System.out.println(log);
    }

    @Around("method()")
    public void aroundtest(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {


        Object[] args = proceedingJoinPoint.getArgs();
        String name =(String) args[0];
        long l = System.currentTimeMillis();
        Object proceed = proceedingJoinPoint.proceed();
        long l1 = System.currentTimeMillis();


        String log = "名字："+name + "在时间为："+(l1-l)+"时间段里执行around 我真服了爸爸 操作";


        System.out.println(log);
    }

    @After("method()")
    public void aftertest(JoinPoint proceedingJoinPoint) {


        Object[] args = proceedingJoinPoint.getArgs();
        String name =(String) args[0];
        LocalDateTime now = LocalDateTime.now();

        String log = "名字："+name + "在时间为："+now+"时执行after操作";
        System.out.println(log);
    }
}
